import 'package:bilibili_getx_project/core/constant/constant.dart';
import 'package:dio/dio.dart';

class HttpBaseRequest {
  static Future<T> request<T>(String baseUrl, String path,
      {method, params}) async {
    method = method ?? 'GET';
    BaseOptions baseOptions = BaseOptions(
      method: method,
      baseUrl: Constants.baseUrlMap[baseUrl]!,
      connectTimeout: 10000,
    );
    Dio dio = Dio(baseOptions);
    try {
      Response response = await dio.request(path, queryParameters: params);
      return response.data;
    } on DioError catch (e) {
      return Future.error(e);
    }
  }
}
